<template>
  <div class="mt-32">
    <div class="card-box box-shadow-ed box-shadow-ed py-32">
      <div class="date-type">
        <div :class="selectDate == '1' && 'select'" @click="changeDate(1)">
          日
        </div>
        <div :class="selectDate == '2' && 'select'" @click="changeDate(2)">
          周
        </div>
        <div :class="selectDate == '3' && 'select'" @click="changeDate(3)">
          月
        </div>
      </div>
      <div class="tip">分类对比</div>
      <div class="card-list">
        <div>
          <div>{{ detail?.totalNum || 0 }}</div>
          <div>总顾客</div>
        </div>
        <div>
          <div>{{ detail?.oldNum || 0 }}</div>
          <div>老顾客</div>
        </div>
        <div>
          <div>{{ detail?.newNum || 0 }}</div>
          <div>新顾客</div>
        </div>
      </div>
      <!-- <div class="bar-box">
        <Gecharts :options="barOptions" class="w-100 h-100"></Gecharts>
      </div> -->
    </div>
    <!-- <div class="card-box box-shadow-ed pie-box">
      <Gecharts :options="pieOptions" class="w-100 h-100"></Gecharts>
    </div> -->
  </div>
</template>

<script setup>
import { onMounted } from "vue";
import { postBusinessNum } from "@/api/index";
import { handlerData as handlerBarData } from "../charts/bar-options.js";
import { handlerData as handlerPieData } from "../charts/pie-options.js";
import moment from "moment";
const selectDate = ref(1);
const currentTime = ref([
  moment(new Date()).startOf("day").format("YYYY-MM-DD HH:mm:ss"),
  moment(new Date()).endOf("day").format("YYYY-MM-DD HH:mm:ss"),
]);
const changeDate = (val) => {
  selectDate.value = val;
  const dateType = dateObj[selectDate.value];
  console.log("dateType", dateType);
  currentTime.value = [
    moment(new Date()).startOf(dateType).format("YYYY-MM-DD HH:mm:ss"),
    moment(new Date()).endOf(dateType).format("YYYY-MM-DD HH:mm:ss"),
  ];
  getData();
};
const dateObj = {
  1: "day",
  2: "week",
  3: "month",
};
const updateDateMsg = (val) => {
  selectDate.value = val;
  const dateType = dateObj[selectDate.value];
  console.log("dateType", dateType);
  currentTime.value = [
    moment(new Date()).startOf(dateType).format("YYYY-MM-DD HH:mm:ss"),
    moment(new Date()).endOf(dateType).format("YYYY-MM-DD HH:mm:ss"),
  ];
};
const detail = ref({
  totalNum: 0,
  oldNum: 0,
  newNum: 0,
});
const barOptions = ref({});
const pieOptions = ref({});
const getData = () => {
  const dateType = dateObj[selectDate.value];
  postBusinessNum({
    startTime: currentTime.value[0],
    endTime: currentTime.value[1],
  }).then((res) => {
    detail.value = res.data;
  });
};

onMounted(() => {
  getData();
  // barOptions.value = handlerBarData();
  // pieOptions.value = handlerPieData();
  console.log(" pieOptions.value", pieOptions.value);
});
</script>

<style lang="less" scoped>
.card-box {
  border-radius: 20px;
  margin: 0 30px;
  background: #fff;
  margin-bottom: 36px;
  position: relative;
  .date-type {
    position: absolute;
    top: 0;
    left: 0;
    font-size: 28px;
    display: flex;
    > div {
      width: 55px;
      height: 65px;
      text-align: center;
      line-height: 65px;
      border: 1px solid #000;
      border-left: none;

      &:first-child {
        border-left: 1px solid #000;
      }
      &.select {
        background: #000;
        color: #fff;
      }
    }
  }
  .tip {
    font-size: 34px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 32px;
  }
}
.card-list {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  padding: 0 30px;
  gap: 30px;
  > div {
    background: #fff;
    // border-radius: 15px;
    padding: 30px 0 10px;
    height: 210px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px #e9e9e9;
    > div:first-child {
      color: #f8b62b;
      font-size: 52px;
      font-weight: 600;
      margin-bottom: 24px;
    }
    > div:last-child {
      color: #f8b62b;
      font-size: 28px;
    }
  }
}
.bar-box {
  height: 500px;
}
.pie-box {
  height: 500px;
  background: #fff;
}
</style>
